package com.isias.system.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.isias.model.system.SysPost;
import com.isias.model.system.SysRole;
import com.isias.model.system.SysUserRole;
import com.isias.model.vo.SysPostQueryVo;
import com.isias.system.mapper.SysPostMapper;
import com.isias.system.mapper.SysUserMapper;
import com.isias.system.service.SysPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional(rollbackFor = Exception.class)
public class SysPostServiceImpl extends ServiceImpl<SysPostMapper, SysPost> implements SysPostService {

    @Autowired
    private SysPostMapper sysPostMapper;

    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 分页查询
     * @param sysPostPage
     * @param sysPostQueryVo
     * @return
     */
    @Override
    public IPage<SysPost> selectPage(Page<SysPost> sysPostPage, SysPostQueryVo sysPostQueryVo) {
        return sysPostMapper.selectPage(sysPostPage,sysPostQueryVo);
    }

    /**
     * 更改岗位状态
     * @param id
     * @param status
     * @return
     */
    @Override
    public boolean changeStatus(String id, Integer status) {
        return sysPostMapper.changeStatus(id, status);
    }

    @Override
    public List<SysPost> GetAll() {
        return sysPostMapper.selectList(null);
    }

    @Override
    public Map<String, Object> getRolesByUserId(String userId) {
        //获取所有身份
        List<SysPost> posts = sysPostMapper.selectIdAndPostName();
        //根据用户id查询出当前的身份
        String userpostid = sysUserMapper.getPost(userId);
        //创建返回的Map
        Map<String, Object> returnMap = new HashMap<>();
        returnMap.put("allPosts",posts);
        returnMap.put("userPostId",userpostid);
        return returnMap;
    }


}
